package com.zyw.zhuangdian.util;


import com.zyw.zhuangdian.enums.MsgCode;
import com.zyw.zhuangdian.pojo.Resp;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

public class RespUtil {

    private static ResponseEntity<Resp<?>> wrap(Resp<?> resp,HttpStatus status){
        return new ResponseEntity<>(resp, status);
    }

    public static ResponseEntity<Resp<?>> Response(String code,String msg,Object data,HttpStatus status){
        return wrap(new Resp<>(code,msg,data),status);
    }

    public static ResponseEntity<Resp<?>> OK(Resp<?> data){
        return wrap(data,HttpStatus.OK);
    }
    public static ResponseEntity<Resp<?>> OK(MsgCode msg){
        Resp<?> resp= new Resp<>(msg.getCode(), msg.getMsg(), null);
        return wrap(resp,HttpStatus.OK);
    }
    public static ResponseEntity<String> OK(String jsonString){
        return new ResponseEntity<>(jsonString,HttpStatus.OK);
    }

    public static ResponseEntity<Resp<?>> UN_AUTH(Resp<?> data){
        return wrap(data,HttpStatus.UNAUTHORIZED);
    }
    public static ResponseEntity<Resp<?>> UN_AUTH(MsgCode msg){
        Resp<?> resp= new Resp<>(msg.getCode(), msg.getMsg(), null);
        return wrap(resp,HttpStatus.UNAUTHORIZED);
    }

    public static ResponseEntity<Resp<?>> NOT_FOUND(Resp<?> data){
        return wrap(data,HttpStatus.NOT_FOUND);
    }
    public static ResponseEntity<Resp<?>> SYSTEM_ERROR(Resp<?> data){
        return wrap(data,HttpStatus.INTERNAL_SERVER_ERROR);
    }
    public static ResponseEntity<Resp<?>> SYSTEM_ERROR(MsgCode msg){
        Resp<Object> resp= new Resp<>(msg.getCode(), msg.getMsg(), null);
        return wrap(resp,HttpStatus.INTERNAL_SERVER_ERROR);
    }

}
